package cn.scw.project.goods.service.impl;

import cn.scw.common.utils.sql.JpaUtil;
import cn.scw.project.goods.domain.GOrderCommodity;
import cn.scw.project.goods.domain.netework.bean.GOrderCommodityListReq;
import cn.scw.project.goods.domain.vo.GOrderCommodityVo;
import cn.scw.project.goods.mapper.GOrderCommodityMapper;
import cn.scw.project.goods.service.IGOrderCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单商品Service业务层处理
 *
 * @author api
 * @date 2020-05-20
 */
@Service
public class GOrderCommodityServiceImpl implements IGOrderCommodityService {
    @Autowired
    private GOrderCommodityMapper gOrderCommodityMapper;

    /**
     * 查询订单商品
     *
     * @param id 订单商品ID
     * @return 订单商品
     */
    @Override
    public GOrderCommodity selectGOrderCommodityById(Long id) {
        return gOrderCommodityMapper.selectGOrderCommodityById(id);
    }

    @Override
    public GOrderCommodityVo selectGOrderCommodityVoById(Long id) {
        return gOrderCommodityMapper.selectGOrderCommodityVoById(id);
    }

    /**
     * 查询订单商品列表
     *
     * @param req 订单商品
     * @return 订单商品
     */
    @Override
    public List<GOrderCommodityVo> selectGOrderCommodityList(GOrderCommodityListReq req) {
        req.setOrderNumber(JpaUtil.getNullOrLikeStr(req.getOrderNumber()));
        req.setCommodityName(JpaUtil.getNullOrLikeStr(req.getCommodityName()));
        return gOrderCommodityMapper.selectGOrderCommodityList(req);
    }

    @Override
    public List<GOrderCommodityVo> selectGOrderCommodityVoListByOrder(Long orderId) {
        return gOrderCommodityMapper.selectGOrderCommodityVoListByOrder(orderId);
    }

    /**
     * 新增订单商品
     *
     * @param gOrderCommodity 订单商品
     * @return 结果
     */
    @Override
    public int insertGOrderCommodity(GOrderCommodity gOrderCommodity) {
        return gOrderCommodityMapper.insertGOrderCommodity(gOrderCommodity);
    }

    /**
     * 修改订单商品
     *
     * @param gOrderCommodity 订单商品
     * @return 结果
     */
    @Override
    public int updateGOrderCommodity(GOrderCommodity gOrderCommodity) {
        return gOrderCommodityMapper.updateGOrderCommodity(gOrderCommodity);
    }

    /**
     * 批量删除订单商品
     *
     * @param ids 需要删除的订单商品ID
     * @return 结果
     */
    @Override
    public int deleteGOrderCommodityByIds(Long[] ids) {
        return gOrderCommodityMapper.deleteGOrderCommodityByIds(ids);
    }

    /**
     * 删除订单商品信息
     *
     * @param id 订单商品ID
     * @return 结果
     */
    @Override
    public int deleteGOrderCommodityById(Long id) {
        return gOrderCommodityMapper.deleteGOrderCommodityById(id);
    }

    @Override
    public int countByUserAndRent(Long userId, String purchasingTypes) {
        return gOrderCommodityMapper.countByUserAndRent(userId,purchasingTypes);
    }
}
